package xmlimporter;

import java.beans.XMLDecoder;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import entry.Entry;
import shortcuthelper.Importer;

public class XmlImporter implements Importer {

	private List<Entry> entryList = new ArrayList<Entry>();

	public boolean isEntryListEmpty() {
		return entryList.isEmpty();
	}

	public Object deserializeXMLtoObject(File XmlFile)
			throws FileNotFoundException {
		FileInputStream os = new FileInputStream(XmlFile);
		XMLDecoder decoder = new XMLDecoder(os);
		Object deserializedObject = decoder.readObject();
		decoder.close();

		return deserializedObject;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Entry> importEntries(File source) throws IOException {
		entryList = (List<Entry>) deserializeXMLtoObject(source);
		return entryList;
	}

}
